//
//  HeaderView.m
//  HeadDemo
//
//  Created by yr on 2019/5/10.
//  Copyright © 2019 yr. All rights reserved.
//

#import "HeaderView.h"


#define TabHeadHeight 204
#define MovedHeadHeight 64

@interface HeaderView ()

@end

@implementation HeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setSubview];
    }
    return self;
}

- (void)setSubview
{
    
    [self addSubview:self.imageView];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self);
    }];
    
    [self addSubview:self.flagIcon];
    
    [self.flagIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.top.equalTo(self).offset(kNavBarHeight + 28);
    }];
    
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.flagIcon);
        make.left.equalTo(self.flagIcon.mas_right).offset(4);
    }];
    
    [self addSubview:self.watchLb];
    [self.watchLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.flagIcon);
        make.top.equalTo(self.flagIcon.mas_bottom).offset(16);
    }];
    
}
- (void)updateLayoutAtOffset:(CGPoint)offset{
    
}
#pragma mark -------
- (UIImageView *)imageView
{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        _imageView.image = [UIImage imageNamed:@"common_topic_bg_tag"];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _imageView;
}
- (UILabel *)watchLb{
    if (!_watchLb) {
        _watchLb = [[UILabel alloc]init];
        _watchLb.text = @"";
        _watchLb.textColor = RGBA(190, 190, 190, 1);
        _watchLb.font = font(12);
    }
    return _watchLb;
}
- (UIImageView *)flagIcon{
    if (!_flagIcon) {
        _flagIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_topic_nav_tag"]];
    }
    return _flagIcon;
}
- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [[UILabel alloc]init];
        _titleLb.textColor = [UIColor whiteColor];
        _titleLb.font = [UIFont boldSystemFontOfSize:20];
    }
    return _titleLb;
}

- (void)setModel:(HomePageTopicDetailModel *)model{
    _model = model;
    _titleLb.text = model.topicName;
    NSString *title = @"";
    if (model.watchNum.intValue >= 10000) {
        NSInteger count = model.watchNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        title = [NSString stringWithFormat:@"%@w次浏览",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        title = [NSString stringWithFormat:@"%@次浏览",model.watchNum];
    }
    _watchLb.text = title;
}

@end
